Skip to content

test: catch expected UserWarning in test_repr_mimebundle_selection_logic - #17717

Merged
shuoweil merged 4 commits into
mainfrom
shuowei-test-render-mode-warning
Jul 16, 2026
Merged

test: catch expected UserWarning in test_repr_mimebundle_selection_logic#17717
shuoweil merged 4 commits into
mainfrom
shuowei-test-render-mode-warning

Conversation

@shuoweil

@shuoweil shuoweil commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Assert expected UserWarning during the fallback path test in test_repr_mimebundle_selection_logic.
When testing fallback behavior on anywidget failure, html.repr_mimebundle emits a warning (Anywidget mode is not available or failed to load). This change uses pytest.warns(UserWarning, match=...) to handle the warning cleanly in unit tests.

Fixes #<534917716> 🦕

@shuoweil shuoweil self-assigned this Jul 15, 2026
@shuoweil
shuoweil requested review from a team as code owners July 15, 2026 00:01

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the unit tests in test_render_mode.py to import pytest and assert that a UserWarning with the message 'Anywidget mode is not available' is correctly raised when anywidget fails during deferred representation rendering. I have no feedback to provide as there are no review comments.

@sycai sycai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Small PRs are the best

with bpd.option_context("display.repr_mode", "deferred"):
bundle = bf_html.repr_mimebundle(mock_obj)
with pytest.warns(UserWarning, match="Anywidget mode is not available"):
bundle = bf_html.repr_mimebundle(mock_obj)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can chain multiple context managers in a single "with" statement, separated with commas:

with bpd.option_context(...), pytest.warns(...):
    bundle = ...

Let see if that works

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestions. I have applied the same changes to all anywidget related testcase. Thanks again for your suggestions.

@shuoweil
shuoweil requested a review from sycai July 15, 2026 18:37
@shuoweil

Copy link
Copy Markdown
Contributor Author

The failed tests are unrelated to our code change. I have failed a bug to the code owner to get the failed testcase resolved.

@parthea parthea assigned sycai and unassigned shuoweil Jul 15, 2026
@shuoweil
shuoweil merged commit 5d3ca44 into main Jul 16, 2026
39 of 40 checks passed
@shuoweil
shuoweil deleted the shuowei-test-render-mode-warning branch July 16, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants